package com.linchaoen.elema.controller;

import com.linchaoen.elema.model.entity.Test;
import com.linchaoen.elema.model.request.TestRequest;
import com.linchaoen.elema.service.TestService;
import com.linchaoen.elema.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/v1/pub/test")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("add")
    public JsonData add(@RequestBody TestRequest testRequest) {
        List<String> nameList = testRequest.getNameList();
        List<Integer> ageList = testRequest.getAgeList();
        List<Test> testList = new ArrayList<>();
        for (int i = 0; i < nameList.size(); i++) {
            Test test = new Test();
            for (int j = 0; j < ageList.size(); j++) {
                test.setName(nameList.get(i));
                test.setAge(ageList.get(i));
                testList.add(test);
                break;
            }
        }
        int i = testService.saveBatch(testList);
        return JsonData.buildSuccess();
    }

}
